package com.nononsenseapps.feeder.db.room

import androidx.room.*
import cn.ekuma.odbo.mobile.room.BaseDao
import com.nononsenseapps.feeder.db.entity.FeedItemFeature

@Dao
interface FeedItemFeatureDao : BaseDao<FeedItemFeature> {

    @Query("SELECT * FROM feed_item_feature ORDER BY create_date DESC")
    fun listFeedItemFeature(): List<FeedItemFeature>

    @Query("SELECT * FROM feed_item_feature WHERE id IS :key")
    fun get(key: Long): FeedItemFeature
}

fun FeedItemFeatureDao.upsert(item: FeedItemFeature): Long = when (item.id > ID_UNSET) {
    true -> {
        update(item)
        item.id
    }
    false -> {
        val id=insert(item)
        item.id=id
        id
    }
}